/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : levelLogic
	/// </summary>
	public class LevelPlayerSavePOD : IPOD 
    {
        public readonly static Func<LevelPlayerSavePOD> FACTORY = () => new LevelPlayerSavePOD();
		public static Func<LevelPlayerSavePOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public long pid;
		/// <summary>
        /// 
        /// </summary>
		public int regionCid;
		/// <summary>
        /// 
        /// </summary>
		public int checkPointId;
		/// <summary>
        /// 
        /// </summary>
        private List<LevelBuffPOD> m_buffs;
		/// <summary>
        /// 
        /// </summary>
		public int followEntityId;
		/// <summary>
        /// 策划自定义相机参数
        /// </summary>
		public int customCameraCid;
		/// <summary>
        /// 
        /// </summary>
		public LevelEntityPOD heroEntity;
		/// <summary>
        /// 
        /// </summary>
		public bool isQuickBarDisabled;
		
		
        public List<LevelBuffPOD> buffs
        {
            get
            {
                if(m_buffs == null)
                {
                    m_buffs = new();
                }
                return m_buffs;
            }
            private set => m_buffs = value;
        }
        public List<LevelBuffPOD> unsafe_buffs
        {
        	get => m_buffs;
        	set => m_buffs = value;
        }
		
		/*-- constructors --*/
		public LevelPlayerSavePOD() {}
		public LevelPlayerSavePOD(long pid, int regionCid, int checkPointId, List<LevelBuffPOD> buffs, int followEntityId, int customCameraCid, LevelEntityPOD heroEntity, bool isQuickBarDisabled) {
			this.pid = pid;
			this.regionCid = regionCid;
			this.checkPointId = checkPointId;
			this.m_buffs = buffs;
			this.followEntityId = followEntityId;
			this.customCameraCid = customCameraCid;
			this.heroEntity = heroEntity;
			this.isQuickBarDisabled = isQuickBarDisabled;
		}
		  public void Serial(SOutputStream _out) {
                if(pid != default) {
                    _out.WriteByte(1);
                    _out.Write_long(pid);
                }
                if(regionCid != default) {
                    _out.WriteByte(2);
                    _out.Write_int(regionCid);
                }
                if(checkPointId != default) {
                    _out.WriteByte(3);
                    _out.Write_int(checkPointId);
                }
                if(m_buffs != default) {
                    _out.WriteByte(4);
                    _out.Write_list_pod(m_buffs);
                }
                if(followEntityId != default) {
                    _out.WriteByte(5);
                    _out.Write_int(followEntityId);
                }
                if(customCameraCid != default) {
                    _out.WriteByte(6);
                    _out.Write_int(customCameraCid);
                }
                if(heroEntity != default) {
                    _out.WriteByte(7);
                    _out.Write_pod(heroEntity);
                }
                if(isQuickBarDisabled != default) {
                    _out.WriteByte(8);
                    _out.Write_boolean(isQuickBarDisabled);
                }
        }
            
        public void UnSerial(SInputStream _in) {
            while (_in.HasRemaining())
            {
                int _key = _in.ReadByte();
                switch (_key)
                {
                    case 1:
                        pid = _in.Read_long();
                        break;
                    case 2:
                        regionCid = _in.Read_int();
                        break;
                    case 3:
                        checkPointId = _in.Read_int();
                        break;
                    case 4:
                        m_buffs = _in.Read_list_pod<LevelBuffPOD>(LevelBuffPOD.DynamicFactory);
                        break;
                    case 5:
                        followEntityId = _in.Read_int();
                        break;
                    case 6:
                        customCameraCid = _in.Read_int();
                        break;
                    case 7:
                        heroEntity = _in.Read_pod<LevelEntityPOD>(LevelEntityPOD.DynamicFactory);
                        break;
                    case 8:
                        isQuickBarDisabled = _in.Read_boolean();
                        break;
                    default: _in.SkipBinary();break;
                }
            }
        }
		
		public LevelPlayerSavePOD Clone() {
            LevelPlayerSavePOD o = DynamicFactory();
            o.pid = pid;
            o.regionCid = regionCid;
            o.checkPointId = checkPointId;
            if (m_buffs != null) {
                o.m_buffs = m_buffs.ConvertAll(o => o?.Clone());
            }
            o.followEntityId = followEntityId;
            o.customCameraCid = customCameraCid;
            if (heroEntity != null) {
                o.heroEntity = heroEntity.Clone();
            }
            o.isQuickBarDisabled = isQuickBarDisabled;
            return o;
        }
        
        public void Clear() {
            pid = default;
            regionCid = default;
            checkPointId = default;
            m_buffs = default;
            followEntityId = default;
            customCameraCid = default;
            heroEntity = default;
            isQuickBarDisabled = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "LevelPlayerSavePOD [";
			str += "pid=";
			str += pid;
			str += ", regionCid=";
			str += regionCid;
			str += ", checkPointId=";
			str += checkPointId;
			str += ", buffs=";
			str += m_buffs.ToString<LevelBuffPOD>();
			str += ", followEntityId=";
			str += followEntityId;
			str += ", customCameraCid=";
			str += customCameraCid;
			str += ", heroEntity=";
			str += heroEntity;
			str += ", isQuickBarDisabled=";
			str += isQuickBarDisabled;
			str += "]";
			return str;
		}
		
	}
}